// pages/record/list/list.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		list: []
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		wx.request({
			url: getApp().globalData.http + 'action=getByList',
			success: (e) => {
				console.log(e)
				this.setData({
					id:options.id,
					data: e.data.data
				})
			}
		})
	},
	bindTimeChange: function(e) {
		console.log(e)
		this.setData({
			time: e.detail.value
		})
	},
	journey(e) {
		this.setData({
			journey: e.detail.value
		})
	},
	gb(e) {
		let a = this.data.data
		let b=this.data.list
		a.forEach(function(item, index) {
				if (e.currentTarget.dataset.id == index) {
					if (a[index].state == undefined || a[index].state == 0) {
						a[index].state = 1
						b.push(a[index].names)
					} else {
						a[index].state = 0
						b.forEach(function(item,c){
							if(b[c]==a[index].names){
								b.splice(c,1)
							}
						})
					}
				}
			})
			console.log(b)
			this.setData({
				data: a,
				list:b
			})
		},
		over(){
			if(this.data.time!=undefined&&this.data.journey!=undefined&&this.data.list.length!=0){
				let a=this.data.list
				a.join(',')
				wx.request({
					url:getApp().globalData.http +'action=addBaoYang&carid='+this.data.id+'&bytime='+
					this.data.time+'&millions='+this.data.journey+'&byxm='+a,
					success:(e)=>{
						console.log(e)
					}
				})
			}else{
				wx.showToast({
					icon:'none',
					title:'有未选项'
				})
			}
			
		}
})
